/**
 * Project Name:SimonFramework
 * File Name:ProcessAndDisplayImageTask.java
 * Package Name:com.simon.framework.image.core
 * Date:2016-5-19 下午1:58:47
 * Copyright (c) 2016, simon@cmonbaby.com All Rights Reserved.
 */
package com.cmonbaby.images.core;

import android.graphics.Bitmap;
import android.os.Handler;

import com.cmonbaby.images.core.assist.LoadedFrom;
import com.cmonbaby.images.core.process.BitmapProcessor;
import com.cmonbaby.images.utils.LogUtils;

/**
 * <p>Author:      Simon
 * <p>QO:          8950764
 * <p>Email:       simon@cmonbaby.com
 * <p>WebSize:     https://www.cmonbaby.com
 * <p>Version:     1.0.0
 * <p>Date:        2020/12/29
 * <p>Description: 图像任务加载，位图处理图像并显示
 */
final class ProcessAndDisplayImageTask implements Runnable {

	private static final String LOG_POSTPROCESS_IMAGE = "PostProcess image before displaying [%s]";

	private final ImageLoaderEngine engine;
	private final Bitmap bitmap;
	private final ImageLoadingInfo imageLoadingInfo;
	private final Handler handler;

	public ProcessAndDisplayImageTask(ImageLoaderEngine engine, Bitmap bitmap, ImageLoadingInfo imageLoadingInfo,
									  Handler handler) {
		this.engine = engine;
		this.bitmap = bitmap;
		this.imageLoadingInfo = imageLoadingInfo;
		this.handler = handler;
	}

	@Override
	public void run() {
		LogUtils.d(LOG_POSTPROCESS_IMAGE, imageLoadingInfo.memoryCacheKey);

		BitmapProcessor processor = imageLoadingInfo.options.getPostProcessor();
		Bitmap processedBitmap = processor.process(bitmap);
		DisplayBitmapTask displayBitmapTask = new DisplayBitmapTask(processedBitmap, imageLoadingInfo, engine,
				LoadedFrom.MEMORY_CACHE);
		LoadAndDisplayImageTask.runTask(displayBitmapTask, imageLoadingInfo.options.isSyncLoading(), handler, engine);
	}

}

